var ScreenSaver = function(pid)
{
	this.rootid = pid;
	this.rows = 10;
	this.cols = 10;
	this.intervalid = 0;
	try
	{
		this.rows = parseInt(document.getElementById(this.rootid).getAttribute("rows"));
		this.cols = parseInt(document.getElementById(this.rootid).getAttribute("cols"));
	}catch(err){}
	this.instancename = document.getElementById(this.rootid).getAttribute("instancename");
	this.cellmax = this.rows * this.cols;

	this.randcolor = function()
	{
		var ret = "rgba(";
		for(var icnt = 0; icnt < 3; icnt++)
		{
			ret += (Math.floor(Math.random() * 255).toString() + ",");
		}
		ret += "0.4)";
		return ret;
	}

	this.display = function()
	{
		var myc = document.body.appendChild(document.createElement("canvas"));
		myc.setAttribute("id", "qwer");
		myc.style.position = "absolute";
		myc.style.zIndex = 100;
		myc.style.left = 0;
		myc.style.top = 0;
		myc.width = window.innerWidth;
		myc.height = window.innerHeight;
		var mycx = myc.getContext("2d");
		mycx.beginPath();
		mycx.fillStyle = "rgba(0,0,0,0.7)";
		mycx.fillRect(0, 0, myc.width, myc.height);
		mycx.font = "150px 'Impact'";
		mycx.fillStyle = "white";
		mycx.fillText("Manipulator", 500, 400);
		mycx.fillStyle = this.randcolor();
		mycx.fillText("M", 500, 400);
		mycx.closePath();
		myc.setAttribute("onclick", "var mya=document.getElementById('asdf'); mya.parentNode.removeChild(mya);mya=document.getElementById('qwer'); mya.parentNode.removeChild(mya);");

		var  mydiv = document.body.appendChild(document.createElement("div"));
		mydiv.setAttribute("id", "asdf");
		mydiv.setAttribute("rows", "10");
		mydiv.setAttribute("cols", "10");
		mydiv.style.position = "absolute";
		mydiv.style.left = "150px";
		mydiv.style.top = "200px";
		mydiv.style.zIndex = 101;
		var a = document.getElementById("asdf");
		rows = parseInt(a.getAttribute("rows"));
		cols = parseInt(a.getAttribute("cols"));
		cellmax = rows * cols;

		var t = a.appendChild(document.createElement("table"));
		t.setAttribute("cellspacing", "10");
		var cellcount = 0;
		for(var rcnt = 0; rcnt < rows; rcnt++)
		{
			var r = t.appendChild(document.createElement("tr"));
			for(var ccnt = 0; ccnt < cols; ccnt++)
			{
				var d = r.appendChild(document.createElement("td"));
				var c = d.appendChild(document.createElement("canvas"));
				c.width = 10;
				c.height = 10;
				c.setAttribute("id", cellcount.toString());
				var cx = c.getContext("2d");
				cx.beginPath();
				cx.fillStyle = this.randcolor();
				cx.fillRect(0, 0, c.width, c.height);
				cx.closePath();
				cellcount++;
			}
		}
		this.intervalid = setInterval(this.instancename + ".changecolor();", 10);
	}

	this.changecolor = function()
	{
		var c = document.getElementById(Math.floor(Math.random() * cellmax).toString());
		var cx = c.getContext("2d");
		cx.beginPath();
		cx.fillStyle = this.randcolor();
		cx.fillRect(0, 0, c.width, c.height);
		cx.closePath();
	}

}
